#include <iostream>
using namespace std;

class Product{
	public:
		Product(){
			cout<<"Product.Des"<<endl;
		}
		virtual void Operation()=0;
		virtual ~Product(){
			cout<<"Product.Des"<<endl;
		}
};

class Factory {
	private:
		Product *p;
	public:
		Factory(Product *_p){
			p=_p;		
		}
		void Creat(){
			p->Operation();
		} 
		~Factory(){
			delete p;
		}
};

class FactoryA:public Factory{
	public:
		FactoryA(Product *_p):Factory(_p){}
};

class FactoryB:public Factory{
	public:
		FactoryB(Product *_p):Factory(_p){}
};

class ProA:public Product{
	public:
		void Operation() {
			cout<<"ProA Done"<<endl;
		}
		~ProA() {
			cout <<"ProA.Des"<<endl;
		}
};

class ProB:public Product{
	public:
		void Operation() {
			cout<<"ProB Done"<<endl;
		}
		~ProB() {
			cout <<"ProB.Des"<<endl;
		}
};

int main(void){
	Factory * pF=new FactoryA(new ProB());
	pF->Creat();
	delete pF;
	return 0;
}
